package com.ithema.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.ithema.dao.OrderDao;
import com.ithema.domain.Order;
import com.ithema.service.OrderService;
import com.ithema.util.JsonConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author wangyu
 * @Date 2021/10/31
 */
@Slf4j
@Service
public class OrderServiceImpl3 implements JsonConverter {

    @SentinelResource(
            value = "message",
            blockHandler = "blockHandler",
            fallback = "fallback",
            blockHandlerClass = OrderServiceImpl3BlockHandler.class,
            fallbackClass = OrderServiceImpl3Fallback.class
    )
    public String message(String name) {
        log.info("message " + name);
        return "message " + name;
    }

    //1. 当前方法的返回值和参数要与原方法一致
    //2. 但允许方法参数列表的最后加入一个参数Bloack
//    public String blockHandler(String name, BlockException e){
//        log.error("name={}, BlockException={}", name, e);
//        return "BlockException";
//    }

    //1. 当前方法的返回值和参数要与原方法一致
    //2. 但允许方法参数列表的最后加入一个参数Bloack
//    public String fallback(String name, Throwable e){
//        log.error("name={}, Throwable={}", name, e);
//        return "Throwable";
//    }

}
